#encoding = utf - 8

#自定义的函数
import pygame
import math


'''
计算到圆点的距离
参数：
x：当前的X轴坐标
y：当前的Y轴坐标
'''
def mathToDotSpacing(self, x, y):
    "计算到原点的距离"
    return math.sqrt(x * x + y * y)


'''
利用三角函数计算随机两点间的距离（复杂矢量化）
'''
def mathTwoPointSpacing(self):
    "利用三角函数计算玩家和怪物之间的距离（复杂矢量化）"
    spacingMonster = self.mathToDotSpacing(self.rect.left, self.rect.top)  # 自己到圆点的距离
    spacingPlayer = self.mathToDotSpacing(self.player.rect.left, self.player.rect.top)  # 计算玩家到圆点的距离
    angleMonster = self.mathAngle(self.rect.left, self.rect.top)  # 计算到圆点的夹角
    anglePlayer = self.mathAngle(self.player.rect.left, self.player.rect.top)  # 计算玩家到圆点的夹角
    includedAngle = abs(angleMonster - anglePlayer)
    floSpacing = math.sqrt(
        spacingMonster * spacingMonster + spacingPlayer * spacingPlayer - 2 * spacingMonster * spacingPlayer * math.cos(
            math.radians(includedAngle)))
    return floSpacing


class SetPlayerImages():
    #获取玩家图片
    def getPlayerImages(playerType):
        if playerType == "typePig":
            pass
        elif playerType == "typeMonkey":
            pass
        elif playerType == "typeRabbit":
            pass
        elif playerType == "typeDragon":
            pass

class MathAngleAndDirection():

    #计算角度
    def mathAngle(self, differX, differY):
        angle = 360 - math.atan2(differY, differX) * (180 / math.pi)  # 角度
        if angle >= 360:
            angle -= 360
        return angle

    #根据角度计算方向，以对方的位置减自己的位置
    def mathAngleToDirection(self, differX, differY):
        angle = self.mathAngle(differX, differY)
        if angle >=23 and angle < 68:   #右上
            direction = 1
        elif angle >= 68 and angle < 113:   #上
            direction = 0
        elif angle >= 113 and angle < 158:   #左上
            direction = 7
        elif angle >= 158 and angle < 203:  # 左
            direction = 6
        elif angle >= 203 and angle < 248:  # 左
            direction = 5
        elif angle >= 158 and angle < 293:  # 左
            direction = 4
        elif angle >= 293 and angle < 338:  # 左
            direction = 3
        else:
            direction = 2
        return direction

if __name__ == "__main__":
    m = MathAngleAndDirection()
    x = m.mathAngleToDirection(-190, -240)
    print(x)
